<template>
	<view class="">
		<u-button type="primary" @click="getContext">点击打开会话</u-button>
	</view>
</template>

<script>
	import register from '@/utils/register'
	export default {
		data() {
			return {


			}
		},
		onShow() {
			//this.getContext()
		},
		methods: {
			async getContext() {
				await register(['openEnterpriseChat','getContext','sendChatMessage'])
				await this.$ww.openEnterpriseChat({
					// groupName: '讨论组',
					//wmdaLeBwAAMOjyXoWA85Pqeihl-qCLSg   true
					externalUserIds: ["wmdaLeBwAA4V0DhzRmw3HxMNCoLxSNng"],
					//wmdaLeBwAAOmbr9NZmCwQka8X1Do2PkQ
				})
				await this.$ww.getContext({
					success: (res)=> {
						//console.log(res,'res');
						//alert(JSON.stringify(res.entry))
						this.entry = JSON.stringify(res.entry) ; //返回进入小程序的入口类型
						if(res.entry == 'normal'){
							this.$u.toast('请到会话框执行该操作！')
							return
						}
						this.sendToMessageBox() //分享到聊天框
						var shareTicket = res.shareTicket;
					},
					fail:(res)=>{
						alert(res)
						//this.$u.toast(JSON.stringify(res))
						//this.$u.toast('此功能，需从侧边栏进入才能确定发送患者，正常使用功能！！！')
						console.log(res);
					}
				})
			},
			async sendToMessageBox() {
				this.$ww.sendChatMessage({
					msgtype: "news", //消息类型，必填
					enterChat: true, //为true时表示发送完成之后顺便进入会话，仅移动端3.1.10及以上版本支持该字段
					news:{
						link: "http://www.baidu.com", //H5消息页面url 必填
						title: "百度", //H5消息标题
						desc: "百度链接", //H5消息摘要
						imgUrl: "https://ossapi.169000.net/qwmp/xcxIndexImage/2024/05/24/banner1@2x_20240524141551A001.png", //H5消息封面图片URL
					},
					success: (res)=> {
						//alert(123)
						this.message = JSON.stringify(res)
						this.$u.toast('发送成功！！！')
						//todo:
					},
					fail:(res)=>{
						this.showEorror = JSON.stringify(res)
						//this.$u.toast('请到会话框执行该操作！')
						alert(JSON.stringify(res))
						console.log(res);
					}
				});
			},
		}
	}
</script>